package com.example.demo0

sealed class Format
data class Print(val text:String):Format()
object Newline:Format()

val string = listOf<Format>(Print("Hello"),Newline,Print("Kotlin"))

fun unsafeInterpreter(str:List<Format>){
    str.forEach{
        when(it){
            is Print->print(it.text)
            is Newline-> println()
        }
    }
}


fun stringInterpreter(str:List<Format>)=str.fold(""){
    fullText,s->
    when(s){
        is Print -> fullText + s.text
        is Newline -> fullText + "\n"
    }
}



